﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Medicine.Entity;
using Medicine.Service;
namespace Medicine
{
    public partial class Record : Form
    {
        private User user;
        private RecordService rs = new RecordService();
        public Record(User user)
        {
            this.user = user;
            InitializeComponent();
            listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            listView1.Items.Clear();
            showAllRecord();
        }
        public void showAllRecord()
        {

            MedicineServie ms = new MedicineServie();
            List<RecordDetail> rec_list = rs.queryUserRecord();
            //MessageBox.Show(med_list.Count.ToString());
            foreach (RecordDetail rec in rec_list)//遍历查询出来的数据
            {
                ListViewItem lv = new ListViewItem();
                lv.Text = rec.Med_name;//设置第一行显示的数据
                                            //绑定剩余列的数据
                lv.SubItems.Add(rec.Med_price);
                lv.SubItems.Add(rec.Med_info);
                lv.SubItems.Add(rec.Address);
                lv.SubItems.Add(rec.Remark);
                lv.SubItems.Add(rec.Time);

                //一定记得行数据创建完毕后添加到列表中
                listView1.Items.Add(lv);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String med_name = textBox1.Text.Trim();

            MedicineServie ms = new MedicineServie();
            listView1.Items.Clear();
            if (!med_name.Equals(""))
            {
                List<RecordDetail> rec_list = rs.queryRecordByMedName(med_name);
                //MessageBox.Show(med_list.Count.ToString());
        
                foreach (RecordDetail rec in rec_list)//遍历查询出来的数据
                {
                    ListViewItem lv = new ListViewItem();
                    lv.Text = rec.Med_name;//设置第一行显示的数据
                                           //绑定剩余列的数据
                    lv.SubItems.Add(rec.Med_price);
                    lv.SubItems.Add(rec.Med_info);
                    lv.SubItems.Add(rec.Address);
                    lv.SubItems.Add(rec.Remark);
                    lv.SubItems.Add(rec.Time);

                    //一定记得行数据创建完毕后添加到列表中
                    listView1.Items.Add(lv);
                }
            }
            else {
                showAllRecord();
            }
           
        }
    }

   
}
